package com.yonyou.iuap.jxzy.controller;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONObject;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.yonyou.iuap.base.web.BaseController;
import com.yonyou.iuap.jxzy.entity.AcceptancePaper;
import com.yonyou.iuap.jxzy.service.DomesticPaperModifyService;
import com.yonyou.iuap.mvc.type.SearchParams;

/**
 * 国内废纸个人历史检测数据查询修改
 * @author 王格萍
 * @date 2019年6月28日
 */
@Controller
@RequestMapping(value="/jx_domesticPaperModify")
public class DomesticPaperModifyController extends BaseController{
	private Logger logger = LoggerFactory.getLogger(DomesticPaperController.class);

	@Autowired
	private DomesticPaperModifyService  service;

	/**
	 * 国内废纸历史数据修改提交
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value="/domPapermodify" ,method=RequestMethod.POST)
	@ResponseBody
	public Object domPapermodify(@RequestBody String acceptancepaper,HttpServletRequest request, HttpServletResponse response){
		JSONObject jsonObject=new JSONObject();
		JSONObject acceptancePaperjsonObject= JSONObject.fromObject(acceptancepaper);
		AcceptancePaper acPaper=(AcceptancePaper)JSONObject.toBean(acceptancePaperjsonObject, AcceptancePaper.class);
		try {
			this.service.domPapermodify(acPaper);
		} catch (Exception e) {
			jsonObject.put("message", "提交失败:"+e.getMessage());
			logger.error("提交失败:"+e.getMessage());
			jsonObject.put("success", "error");
			return jsonObject.toString();
		}
		return this.buildSuccess("提交成功！");
	}

	/**
	 * 国内废纸历史数据查询
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value="/queryDomPaper" ,method=RequestMethod.GET)
	@ResponseBody
	public Object queryDomPaper(SearchParams searchParams,HttpServletRequest request, HttpServletResponse response){
		List<AcceptancePaper>  dompaperlist=null;
		JSONObject jsonObject=new JSONObject();
		try {
			Map<String, Object> map=searchParams.getSearchMap();
			/*if(map!=null&&map.get("serialNo")!=null){
				//解密
				String serialNo = new String(Base64Util.decode(map.get("serialNo").toString()));
				map.put("serialNo", serialNo);
			}*/
			dompaperlist=this.service.queryDomPaper(map);
		} catch (Exception e) {
			jsonObject.put("message", "查询国内废纸历史数据接口异常:"+e.getMessage());
			jsonObject.put("success", "error");
			return jsonObject.toString();
		}
		return this.buildSuccess(dompaperlist);
	}

}
